package com.lesshassles.controller;

import javax.servlet.http.*;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.lesshassles.model.*;
import com.lesshassles.util.*;

public class HttpRequestInterceptor extends HandlerInterceptorAdapter {
	private String signInPage;
	private ApplicationSecurityManager applicationSecurityManager;

	public boolean preHandle(
		HttpServletRequest request,
		HttpServletResponse response,
		Object handler) throws Exception {
		
        User user = (User) applicationSecurityManager.getUser(request);
		if (user == null) {
			response.sendRedirect(this.signInPage);
			return false;
		}

		return true;
	}

	public String getSignInPage() {
		return signInPage;
	}

	public void setSignInPage(String signInPage) {
        this.signInPage = signInPage;
    }

    public ApplicationSecurityManager getApplicationSecurityManager() {
        return applicationSecurityManager;
    }

    public void setApplicationSecurityManager(ApplicationSecurityManager applicationSecurityManager) {
        this.applicationSecurityManager = applicationSecurityManager;
    }
}
